/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __do_l7_default_command .c                         */
/*  NOTE      =                                                    */
/*  DATE      = 2016/03/07 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>
#include <protobuf-c/protobuf-c.h>

#include "frcomm.h"
#include "frmem.h"
#include "frame.h"
#include "client.pb.h"
#include "frsutl.h"
#include "frcmd_server_l7.h"
#include "frame_params.h"
#include "apmtest_cunit.h"


static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

typedef struct __info_action {
    int i_action;  //(0:add/1:del)
    int i_value;
    int l7_proto;
    char *p_value;
    char *p_all_value;
} Info_action;

int __do_l7_default_command(char *p_filename, Info_action *p_st_info, char **pp_result);

void case1(void)
{
    int i_ret = 0;
    char *p_filename = (char *)frstrdup("../analyzer.xml");
    Info_action *p_st_info = NULL;
    char *p_result = NULL;

    p_st_info =(Info_action *)frmalloc(sizeof (Info_action));
    memset(p_st_info, 0x00, sizeof (Info_action));

    p_st_info->i_action = 1;


    i_ret = __do_l7_default_command(p_filename, p_st_info, &p_result);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    frfree(p_st_info);

    if(p_result)
        frfree(p_result);

    frfree(p_filename);

    return;

}


void case2(void)
{
    int i_ret = 0;
    char *p_filename = (char *)frstrdup("../analyzer.xml");
    Info_action *p_st_info = NULL;
    char *p_result = NULL;

    p_st_info =(Info_action *)frmalloc(sizeof (Info_action));
    memset(p_st_info, 0x00, sizeof (Info_action));

    p_st_info->i_action = 0;


    i_ret = __do_l7_default_command(p_filename, p_st_info, &p_result);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    frfree(p_st_info);

    if(p_result)
        frfree(p_result);

    frfree(p_filename);

    return;

}


void case3(void)
{
    int i_ret = 0;
    char *p_filename = (char *)frstrdup("../analyzer1.xml");
    Info_action *p_st_info = NULL;
    char *p_result = NULL;

    p_st_info =(Info_action *)frmalloc(sizeof (Info_action));
    memset(p_st_info, 0x00, sizeof (Info_action));

    p_st_info->i_action = 1;

    i_ret = __do_l7_default_command(p_filename, p_st_info, &p_result);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    frfree(p_st_info);

    if(p_result)
        frfree(p_result);

    frfree(p_filename);

    return;

}



int add_suite()
{
    CU_pSuite pSuite = NULL;

    pSuite = CU_add_suite("__do_l7_default_command 测试", __suite_init, __suite_cleanup);

    if (NULL == pSuite)
    {
        return 1;
    }


    //增加测试用例
    CU_add_test(pSuite, "case1", case1);
    CU_add_test(pSuite, "case2", case2);
    CU_add_test(pSuite, "case3", case3);
//    CU_add_test(pSuite, "case4", case4);
//    CU_add_test(pSuite, "case5", case5);

    return 0;

}

int main(int argc, char **argv)
{
    fr_slab_init(52428800, "test");
    run_cunit(add_suite);
    fr_slab_destroy();

    return 0;
}
